//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "GaussianOrthogonalPolynomial.h"
using namespace Cephei::QL::Math::Integrals;
#undef HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::CGaussianOrthogonalPolynomial (boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phGaussianOrthogonalPolynomial = NULL;
#endif
	_ppGaussianOrthogonalPolynomial = &childNative;
    
}
Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::CGaussianOrthogonalPolynomial (QuantLib::GaussianOrthogonalPolynomial& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phGaussianOrthogonalPolynomial = NULL;
#endif
	_ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (&childNative);
    
    _GaussianOrthogonalPolynomialOwner = owner;
    
}

Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::CGaussianOrthogonalPolynomial (CGaussianOrthogonalPolynomial^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phGaussianOrthogonalPolynomial = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (copy->GetShared());
        
    }
}
Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::CGaussianOrthogonalPolynomial (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phGaussianOrthogonalPolynomial = NULL;
#endif
	if (!t->IsSubclassOf(CGaussianOrthogonalPolynomial::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::CGaussianOrthogonalPolynomial (QuantLib::Handle<QuantLib::GaussianOrthogonalPolynomial>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phGaussianOrthogonalPolynomial = &childNative;
	_ppGaussianOrthogonalPolynomial = &static_cast<boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial>>(childNative.currentLink());
    
    _GaussianOrthogonalPolynomialOwner = owner;
}
Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::CGaussianOrthogonalPolynomial (QuantLib::Handle<QuantLib::GaussianOrthogonalPolynomial> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phGaussianOrthogonalPolynomial = &childNative;
	_ppGaussianOrthogonalPolynomial = &static_cast<boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::CGaussianOrthogonalPolynomial (QuantLib::GaussianOrthogonalPolynomial childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phGaussianOrthogonalPolynomial = NULL;
#endif
	_ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (new QuantLib::GaussianOrthogonalPolynomial (childNative));
    
}
#endif

Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::~CGaussianOrthogonalPolynomial ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppGaussianOrthogonalPolynomial != NULL)
    {
	    delete _ppGaussianOrthogonalPolynomial;
        _ppGaussianOrthogonalPolynomial = NULL;
    }
}
Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::!CGaussianOrthogonalPolynomial ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppGaussianOrthogonalPolynomial != NULL)
    {
	    delete _ppGaussianOrthogonalPolynomial;
    }
}
QuantLib::GaussianOrthogonalPolynomial& Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::GetReference ()
{
    if (_ppGaussianOrthogonalPolynomial == NULL) throw gcnew NativeNullException ();
	return **_ppGaussianOrthogonalPolynomial;
}
boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial>& Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::GetShared ()
{
    if (_ppGaussianOrthogonalPolynomial == NULL) throw gcnew NativeNullException ();
	return *_ppGaussianOrthogonalPolynomial;
}
QuantLib::GaussianOrthogonalPolynomial* Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::GetPointer ()
{
    if (_ppGaussianOrthogonalPolynomial == NULL) throw gcnew NativeNullException ();
	return &**_ppGaussianOrthogonalPolynomial;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GaussianOrthogonalPolynomial>& Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::GetHandle ()
{
	if (_phGaussianOrthogonalPolynomial == NULL)
	{
		_phGaussianOrthogonalPolynomial = new Handle<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussianOrthogonalPolynomial);
	}
	return *_phGaussianOrthogonalPolynomial;
}
#endif
bool Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::HasNative () 
{
	return (_ppGaussianOrthogonalPolynomial != NULL);
}

Double Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::Alpha (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i);
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussianOrthogonalPolynomial)->alpha ( _i );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::Beta (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i);
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussianOrthogonalPolynomial)->beta ( _i );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::Mu_0::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussianOrthogonalPolynomial)->mu_0 ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::Value (UInt64 i, Double x)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i);
        QuantLib::Real _x = (QuantLib::Real)ValueHelper::Convert (x);
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussianOrthogonalPolynomial)->value ( _i,  _x );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::W (Double x)
{
    try
    {
        QuantLib::Real _x = (QuantLib::Real)ValueHelper::Convert (x);
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussianOrthogonalPolynomial)->w ( _x );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::Integrals::CGaussianOrthogonalPolynomial::WeightedValue (UInt64 i, Double x)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i);
        QuantLib::Real _x = (QuantLib::Real)ValueHelper::Convert (x);
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussianOrthogonalPolynomial)->weightedValue ( _i,  _x );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

